#include <linux/memblock.h>

static void *memblock_alloc_internal(phys_addr_t size, phys_addr_t align,
                                     phys_addr_t min_addr, phys_addr_t max_addr,
                                     int nid, bool exact_nid)
{
    phys_addr_t alloc;

    if (max_addr > memblock.current_limit)
        max_addr = memblock.current_limit;

    alloc = memblock_alloc_range_nid(size, align, min_addr, max_addr, nid,
                                     exact_nid);

    /* retry allocation without lower limit */
    if (!alloc && min_addr)
        alloc = memblock_alloc_range_nid(size, align, 0, max_addr, nid,
                                         exact_nid);

    if (alloc)
    {
        alloc = phys_to_virt(alloc);
    }

    return alloc;
}
